<?php

namespace App\Http\Requests\Admin\Ca;

use App\Exceptions\SysException;
use App\Http\Requests\BaseFormRequest;

class HandoverRecordSaveRequest extends BaseFormRequest
{
    protected function passedValidation()
    {
        $from = $this->get('from', 0);
        $to = $this->get('to', 0);
        if ($from == $to) {
            throw new SysException('交接人和接收人不能相同');
        }
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'from' => ['required', 'integer', 'min:1'],
            'to' => ['required', 'integer', 'min:1'],
        ];
    }

    public function messages()
    {
        return [
            'from.required' => '请选择交接人',
            'from.min' => '请选择交接人',
            'to.required' => '请选择接收人',
            'to.min' => '请选择接收人'
        ];
    }
}